home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.003.AnimDemo / AnimDemo.aii next >
Encoding:
Text File  |  1990-06-24  |  25.9 KB  |  1,077 lines  |  [TEXT/MPS ]

  1. *******************************************************************************
  2. * AnimDemo
  3. *
  4. * (C)  Copyright Apple Computer, Inc. 1988-1990
  5. * All rights reserved.
  6. *
  7. * Version 3.0   Jim Mensch
  8. *
  9. * This program is designed to show 3 different styles of animation techniques
  10. * that can be used on the Apple IIgs.
  11. *
  12. * NOTE: This program shows simple animation techniques that can be used as 
  13. * templates for your own applications.  Every attempt has been made to insure 
  14. * maximum understandability of the source code. Speed has been sacrificed for
  15. * clarity in a few of the examples.  Two techniques that are not used here but
  16. * are worth mentioning are Using the vertical count register to know when to
  17. * start drawing (discussed in Apple IIgs tech note #39) and Shielding the
  18. * cursor when using the event manager (discussed in Apple IIgs Tech Note #34).
  19. *
  20. *******************************************************************************
  21. **********************************************************************
  22. *                                                                    *
  23. *           Copyright (c) Apple Computer, Inc. 1988-1990             *
  24. *                       All Rights Reserved                          *
  25. *                                                                    *
  26. *         Developer Technical Support Apple II Sample Code           *
  27. *                                                                    *
  28. *                                                                    *
  29. *                                                                    *
  30. *  ----------------------------------------------------------------  *
  31. *                                                                    *
  32. *     This program and its derivatives are licensed only for         *
  33. *     use on Apple computers.                                        *
  34. *                                                                    *
  35. *     Works based on this program must contain and                   *
  36. *     conspicuously display this notice.                             *
  37. *                                                                    *
  38. *     This software is provided for your evaluation and to           *
  39. *     assist you in developing software for the Apple IIGS           *
  40. *     computer.                                                      *
  41. *                                                                    *
  42. *     DISCLAIMER OF WARRANTY                                         *
  43. *                                                                    *
  44. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  45. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  46. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  47. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  48. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  49. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  50. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  51. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  52. *     REPAIR OR CORRECTION.                                          *
  53. *                                                                    *
  54. *     Apple does not warrant that the functions                      *
  55. *     contained in the Software will meet your requirements          *
  56. *     or that the operation of the Software will be                  *
  57. *     uninterrupted or error free or that defects in the             *
  58. *     Software will be corrected.                                    *
  59. *                                                                    *
  60. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  61. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  62. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  63. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  64. *     WHICH VARY FROM STATE TO STATE.                                *
  65. *                                                                    *
  66. *                                                                    *
  67. **********************************************************************
  68.     eject
  69.     
  70.     case   on
  71.     PRINT  NOHDR,NOGEN
  72.     STRING AsIS
  73.  
  74.     PRINT PUSH,OFF
  75.     INCLUDE 'M16.Util'
  76.     INCLUDE 'M16.ProDOS'
  77.     INCLUDE 'M16.QUICKDRAW'
  78.     INCLUDE 'M16.MEMORY'
  79.     Include 'E16.memory'
  80.     INCLUDE 'M16.EVENT'
  81.     INCLUDE 'M16.LOCATOR'
  82.     INCLUDE 'M16.MISCTOOL'
  83.     INCLUDE 'M16.SOUND'
  84.     INCLUDE 'M16.NOTESYN'
  85.     INCLUDE 'M16.TextTOOL'
  86.     INCLUDE 'M16.IntMath'
  87.     PRINT POP
  88.     
  89. DPHandle    equ 0
  90. DPPointer    equ DPHandle+4
  91. Counter    equ DPPointer+4
  92. LastTick    equ Counter+2
  93. temp1    equ LastTick+2
  94. temp2    equ temp1+2
  95. LinePt    equ temp2+2
  96. ScreenTab    equ LinePt+4
  97. MyBitMap    equ ScreenTab+4
  98. MyBitMask    equ MyBitMap+4
  99. CurX    equ MyBitMask+4
  100. CurY    equ CurX+2
  101. DDPoint1    equ CurY+2
  102. DDPoint2    equ DDPoint1+4
  103. DDPoint3    equ DDPoint2+4
  104. DDTemp    equ DDPoint3+4
  105. DDXInc    equ DDTemp+4
  106. DDYInc    equ DDXInc+2
  107.  
  108. ScreenMode    equ 0
  109. ScreenWidth    equ 320
  110.  
  111.     EJECT
  112. *******************************************************************************
  113. *
  114. AnimDemo    PROC
  115. *
  116. * Description:    This is the main loop of the animation demo
  117. *
  118. *
  119. * Inputs:    None
  120. *
  121. * Outputs:    None
  122. *
  123. * External Refs:
  124.     Import InitTools
  125.     Import InitApp
  126.     Import MainLoop
  127.     Import CloseApp
  128.     Import CloseTools
  129.     Import QuitParms
  130. *
  131. * Entry Points:
  132. *
  133. *******************************************************************************
  134.  
  135.     jsr InitTools
  136.     jsr InitApp
  137.     jsr MainLoop
  138.     jsr CloseApp
  139.     jsr CloseTools
  140.  
  141.     _Quit QuitParms
  142.  
  143.     EndP
  144.  
  145.  
  146.     EJECT
  147. *******************************************************************************
  148. *
  149. Globals    Record
  150. *
  151. * Description:    Data used throughout the program
  152. *
  153. *
  154. * Inputs:    None
  155. *
  156. * Outputs:    None
  157. *
  158. * External Refs:    None
  159. *
  160. * Entry Points:
  161.     Export QuitParms
  162. *
  163. *******************************************************************************
  164. MyID    ds.W 1    ; application ID
  165. QuitParms    dc.L 0    ; standard parms to make the quit call
  166.     dc.W $00    ; return to the launching application
  167.     dc.W 0
  168.  
  169. DTSString    dc.B 'Apple IIgs Power to Animate',0
  170. AutString    dc.B 'By Jim Mensch Apple DTS',0
  171.  
  172. Trigger    dc.W 0
  173.  
  174. EventRecord
  175. EventWhat    ds.B 2
  176. EventMessage    ds.B 4
  177. EventWhen    ds.B 4
  178. EventWhere    ds.B 4
  179. EventModifiers    ds.B 2
  180.  
  181. Rect    ds.B 8
  182.  
  183. BitMap    dc.W $7700,$7777,$0077 ; Bit maps of our animated character
  184.     dc.W $6607,$7667,$7066
  185.     dc.W $6676,$7667,$6766
  186.     dc.W $6776,$7777,$6776
  187.     dc.W $6776,$0000,$6776
  188.     dc.W $7777,$0000,$7777
  189.     dc.W $7777,$0000,$7777
  190.     dc.W $6776,$0000,$6776
  191.     dc.W $6776,$7777,$6776
  192.     dc.W $6676,$7667,$6766
  193.     dc.W $6607,$7667,$7066
  194.     dc.W $7700,$7777,$0077
  195.  
  196. BitMask    dc.W $FF00,$FFFF,$00FF ; Mask of our animated character
  197.     dc.W $FF0F,$FFFF,$F0FF ; to be used for seethru drawing
  198.     dc.W $FFFF,$FFFF,$FFFF
  199.     dc.W $FFFF,$FFFF,$FFFF
  200.     dc.W $FFFF,$0000,$FFFF
  201.     dc.W $FFFF,$0000,$FFFF
  202.     dc.W $FFFF,$0000,$FFFF
  203.     dc.W $FFFF,$0000,$FFFF
  204.     dc.W $FFFF,$FFFF,$FFFF
  205.     dc.W $FFFF,$FFFF,$FFFF
  206.     dc.W $FF0F,$FFFF,$F0FF
  207.     dc.W $FF00,$FFFF,$00FF
  208.  
  209. MyDP    ds.W 1    ; My zero page storage
  210.  
  211.  
  212.     EndR
  213.     
  214.     EJECT
  215. *******************************************************************************
  216. *
  217. InitTools    PROC
  218. *
  219. * Description:    Routine that loads and starts up all the tools that we will
  220. *    be using in this program
  221. *
  222. *
  223. * Inputs:    None
  224. *
  225. * Outputs:    None
  226. *
  227. * External Refs:    
  228.     Import FatalError
  229. *
  230. * Entry Points:    None
  231. *
  232. *******************************************************************************
  233.     With Globals
  234. ;
  235. ;   Tool Direct page offsets here
  236. ;
  237. QDDPage    equ $0000
  238. EMDPage    equ QDDPage+$0300
  239. SEQDPage    equ EMDPage+$0100
  240. ToolDPSize    equ SEQDPage+$0200
  241.  
  242.     phk    ; Save program bank register and
  243.     plb    ; load it as the data bank register
  244.  
  245.     tdc
  246.     sta MyDP    ; Save direct register
  247.  
  248.     _TLStartup    ; Start Tool Locator
  249.  
  250.     PushWord    ; Space for result
  251.     _MMStartup    ; Start memory manager
  252.     PullWord MyID    ; Save it for later use
  253.  
  254.     _MTStartup    ; Start up Misc Tools
  255.  
  256.     _IMStartup    ; Start integer math toolset
  257.  
  258. ;    PushLong #ToolTable    ; Pointer to Tool table
  259. ;    _LoadTools    ; Load all RAM based tools
  260. ;    bcc IT0005    ; Carry clear means no error
  261. ;    brl FatalError    ; Tools can't be loaded. Fatal error!
  262.  
  263. IT0005
  264.  
  265. ; Get memory for Tool Direct pages
  266.  
  267.     PushLong #0    ; Room for result
  268.     PushLong #ToolDPSize; Number of bytes needed
  269.     PushWord MyID    ; ID of this application
  270.     PushWord #attrLocked+attrFixed+attrPage+attrBank
  271.     PushLong #0    ; Allocate them in bank 0
  272.     _NewHandle
  273.     bcc IT0010    ; Test carry for error
  274.     brl FatalError    ; If no memory we got a fatal error!
  275.  
  276. IT0010    PullLong DPHandle    ; Retrieve handle to our DPage area
  277.  
  278.     lda [DPHandle]    ; Dereference the handle to get a ptr
  279.     sta DPPointer    ; to our direct page area and save it.
  280.  
  281.     PushWord DPPointer    ; QuickDraw uses 3 pages of Dpage
  282.     PushWord #ScreenMode; Used to set all master SCB's
  283.     PushWord #0    ; Zero means use default buf size
  284.     PushWord MyID    ; Application ID for allocating data
  285.     _QDStartup    ; Start QuickDraw, turn on SHR Screen
  286.     bcc IT0015
  287.     brl FatalError    ; If it can't be started then bomb
  288.  
  289. IT0015
  290.     lda DPPointer    ; Create address for Event Mgr DPage by
  291.     clc    ; loading in the pointer to the start
  292.     adc #EMDPage    ; of DPage and adding Evt Mgr offset.
  293.     pha    ; Now push it on the stack.
  294.     PushWord #20    ; Size of event queue.
  295.     PushWord #0    ; MouseClamp values.
  296.     PushWord #ScreenWidth ; These will clamp mouse to screen
  297.     PushWord #0    ; area only.
  298.     PushWord #200
  299.     PushWord MyID
  300.     _EMStartup    ; Start the event manager
  301.     bcc IT0020
  302.     brl FatalError    ; Event manager is also a must
  303. IT0020
  304.  
  305.     RTS
  306. ToolTable    dc.W 2
  307.     dc.W 25,$0100    ; note synth
  308.     dc.W 26,$0100    ; note sequencer
  309.  
  310.     EndP
  311.     
  312.     
  313.     EJECT
  314. *******************************************************************************
  315. *
  316. FatalError    PROC
  317. *
  318. * Description:    Routine that is called whenever a tool sends back an error
  319. *    that can not be recovered from. This routine prints the
  320. *    error on the screen, waits for a keypress then quits back
  321. *    to whoever started this application up!
  322. *
  323. *
  324. * Inputs:    A = Error number
  325. *
  326. * Outputs:    NONE (program exits)
  327. *
  328. * External Refs:
  329.     import CloseTools
  330. *
  331. * Entry Points:    NONE
  332. *
  333. *******************************************************************************
  334.     with Globals
  335.  
  336.     pha    ; Push the error code
  337.     PushLong #ErrNumStr    ; Address of storage area
  338.     PushWord #4    ; Length of string
  339.     _Int2Hex
  340.  
  341.     _GrafOff    ; If QD Started, shut off graphics
  342.  
  343.     PushLong #ErrStr    ; Write error message to the screen
  344.     _WriteCString
  345.  
  346.     pha    ; Space for result
  347.     PushWord #0    ; No echo
  348.     _ReadChar    ; Wait for a key to be pressed
  349.     pla    ; Discard the key
  350.  
  351.     jsr CloseTools    ; Shut down all the tools in case
  352. ;          any got started up
  353.  
  354.     _Quit QuitParms    ; Quit back to where we came from.
  355.  
  356.     brk $FF    ; If the quit fails then just break
  357.     
  358. ErrStr    dc.B 'A fatal error has occured $'
  359. ErrNumStr    dc.B 'xxxx   press any key to exit',0
  360.  
  361.     ENDP
  362.  
  363.     EJECT
  364. *******************************************************************************
  365. *
  366. CloseTools    PROC
  367. *
  368. * Description:    Closes all the tools that were started when the application
  369. *    called InitTools.
  370. *
  371. *
  372. * Inputs:    None
  373. *
  374. * Outputs:    None
  375. *
  376. * External Refs:    None
  377. *
  378. * Entry Points:    None
  379. *
  380. *******************************************************************************
  381.     With Globals
  382.  
  383.     _GrafOff
  384.     _EMShutDown
  385.     _QDShutDown
  386.     _MTShutDown
  387.  
  388.     PushLong DPHandle    ; Dispose of all the DP memory
  389.     _DisposeHandle
  390.  
  391.     PushWord MyID
  392.     _MMShutDown
  393.     _TLShutDown
  394.     rts
  395.     EndP
  396.  
  397.  
  398.     EJECT
  399. *******************************************************************************
  400. *
  401. InitApp    PROC
  402. *
  403. * Description:    This procedure will draw the initial screen display and
  404. *    install all the heartbeat tasks for the various animation
  405. *    routines.
  406. *
  407. *
  408. * Inputs:    None
  409. *
  410. * Outputs:    None
  411. *
  412. * External Refs:    None
  413.     Import ScrollTask
  414.     Import LightTask
  415.     Import TrigrTask
  416. *
  417. * Entry Points:    None
  418. *
  419. *******************************************************************************
  420.     With Globals
  421.  
  422.     Stz LinePt    ; use line pt as temp flag!
  423.  
  424.     PushWord #5    ; Erase Screen to DkGreen
  425.     _SetSolidPenPat
  426.  
  427.     PushLong #ScrnRect
  428.     _PaintRect
  429.  
  430.     PushWord #0
  431.     _SetSolidPenPat
  432.  
  433.     PushLong #Marq1Rect    ; Erase the Marquee area to black
  434.     _PaintRect
  435.  
  436.     PushLong #CoinRect    ; Erase the coin area to black
  437.     _PaintRect
  438.  
  439.     Inc CoinRect    ; InsetRect(CoinRect,-1,-1)
  440.     inc CoinRect+2
  441.     dec CoinRect+4
  442.     dec CoinRect+6
  443.  
  444.     PushWord #4    ; give the coin rectangle a green boarded
  445.     _SetSolidPenPat
  446.  
  447.     PushLong #Rect
  448.     _FrameRect
  449.  
  450.  
  451.     lda #20    ; set up a rectangle for the first
  452.     sta Rect    ; Marquee light in the top row 
  453.     sta Rect+2    ; 
  454.     lda #30
  455.     sta Rect+4
  456.     sta Rect+6
  457.  
  458.     PushWord #9    ; draw then in Yellow
  459.     _SetSolidPenPat
  460.     
  461.     jsr DrawLightsH    ; and draw a row of horizontal lights
  462.  
  463.     lda #30
  464.     sta Rect+2    ; update the left and right values of
  465.     lda #40    ; the rectangle to start 10 pixels over
  466.     sta Rect+6    
  467.     
  468.     PushWord #1    ; set the color to dark gray
  469.     _SetSolidPenPat    
  470.     
  471.     jsr DrawLightsH    ; and draw a row of gray lights next to the yellow ones
  472.     
  473.     lda #100    ; Now create the rectangle for the bottom row of 
  474.     sta Rect    ; lights
  475.     lda #30
  476.     sta Rect+2
  477.     lda #110
  478.     sta Rect+4
  479.     lda #40
  480.     sta Rect+6
  481.  
  482.     jsr DrawLightsH    ; and draw this row in Dk Gray
  483.  
  484.     lda #20    ; now reset to draw the yellow lights in this row
  485.     sta Rect+2
  486.     lda #30
  487.     sta Rect+6
  488.     
  489.     PushWord #9
  490.     _SetSolidPenPat
  491.  
  492.     jsr DrawLightsH
  493.  
  494. ; Now draw the vertical lights
  495.     lda #20    ; set up a rectangle for the first
  496.     sta Rect    ; Marquee light in the left column 
  497.     sta Rect+2    ; 
  498.     lda #30
  499.     sta Rect+4
  500.     sta Rect+6
  501.  
  502.     PushWord #9    ; draw then in Yellow
  503.     _SetSolidPenPat
  504.     
  505.     jsr DrawLightsV    ; and draw a Col of vert lights
  506.  
  507.  
  508.     lda #30
  509.     sta Rect    ; update the top and bottom values of
  510.     lda #40    ; the rectangle to start 10 pixels over
  511.     sta Rect+4    
  512.     
  513.     PushWord #1    ; set the color to dark gray
  514.     _SetSolidPenPat    
  515.     
  516.     jsr DrawLightsV    ; and draw a row of gray lights under the yellow 
  517.  
  518.     lda #30    ; Now create the rectangle for the bottom row of 
  519.     sta Rect    ; lights
  520.     lda #290
  521.     sta Rect+2
  522.     lda #40
  523.     sta Rect+4
  524.     lda #300
  525.     sta Rect+6
  526.  
  527.     jsr DrawLightsV    ; and draw this row in Dk Gray
  528.  
  529.     lda #20    ; now reset to draw the yellow lights in this row
  530.     sta Rect
  531.     lda #30
  532.     sta Rect+4
  533.     
  534.     PushWord #9
  535.     _SetSolidPenPat
  536.  
  537.     jsr DrawLightsV
  538.  
  539.     PushWord #15    ; Now, Erase the text area to white
  540.     _SetSolidPenPat
  541.  
  542.     PushLong #Marq2Rect
  543.     _PaintRect
  544.  
  545.     PushWord #0    ; Draw the strings in the marquee
  546.     _SetSolidPenPat
  547.  
  548.     PushWord #50
  549.     PushWord #60
  550.     _MoveTo
  551.  
  552.     PushLong #DTSString
  553.     _DrawCString
  554.  
  555.     PushWord #62
  556.     PushWord #80
  557.     _MoveTo
  558.  
  559.     PushLong #AutString
  560.     _DrawCString
  561.  
  562.     PushLong #0    ; Get the address of the screen 
  563.     PushWord #1    ; address table for use in our
  564.     _GetAddress    ; animation routines
  565.     PullLong ScreenTab
  566.  
  567.     lda #BitMap    ; Now create a pointer to our bitmap
  568.     sta MyBitMap
  569.     lda #BitMap>>16
  570.     sta MyBitMap+2
  571.  
  572.     lda #BitMask    ; Now create a pointer to our bitMask
  573.     sta MyBitMask
  574.     lda #BitMask>>16
  575.     sta MyBitMask+2
  576.  
  577.     lda #20    ; initialize the starting location
  578.     sta CurX    ; of the coin.
  579.     lda #141
  580.     sta CurY
  581.  
  582.     lda #1    ; and set the current increment
  583.     sta DDXInc
  584.     sta DDYInc
  585.  
  586.     PushLong #ScrollTask ;Install the scrolling routine in
  587.     _SetHeartBeat    ; Heart beat queue
  588.  
  589.     PushLong #LightTask    ; install the Marquee light
  590.     _SetHeartBeat    ; heartbeat task
  591.  
  592.     PushLong #TrigrTask    ; and install our heartbeat trigger
  593.     _SetHeartBeat
  594.  
  595.     rts
  596.  
  597. ; The following routine, given the starting rectangle of the first light to draw
  598. ; Will draw a horizontal row of 14 lights across the screen at 20 pixel intervals
  599. DrawLightsH
  600.     stz Counter    ; Init the ligh counter
  601. IA001    PushLong #Rect    ; draw the first light
  602.     _PaintOval
  603.  
  604.     lda Rect+2    ; OffsetRect(Rect,20,0)
  605.     clc    ; do this by adding 20 to Rect.left
  606.     adc #20
  607.     sta Rect+2
  608.     lda Rect+6    ; and rect.right
  609.     clc
  610.     adc #20
  611.     sta Rect+6
  612.  
  613.     ldy Counter    ; bump the counter
  614.     iny
  615.     sty Counter
  616.     cpy #14    ; test to see if we are done
  617.     bne IA001    ; if not, draw another light
  618.     rts    ; if so, then simply end
  619. ;
  620. ; This routine is the same as above only it creates vertical lights
  621. DrawLightsV
  622.     stz Counter
  623. IA011    PushLong #Rect    ; draw the light
  624.     _PaintOval
  625.  
  626.     lda Rect    ; OffsetRect(Rect,0,20)
  627.     clc
  628.     adc #20
  629.     sta Rect
  630.     
  631.     lda Rect+4
  632.     clc
  633.     adc #20
  634.     sta Rect+4
  635.     
  636.     ldy Counter    ; Bump the counter
  637.     iny
  638.     sty Counter
  639.     cpy #4
  640.     bne IA011    ; if not done draw another light
  641.     rts    ; if done, then return
  642.     
  643. ScrnRect    dc.W 0,0,200,320
  644. Marq1Rect    dc.W 18,18,112,302
  645. Marq2Rect    dc.W 32,32,98,288
  646. CoinRect    dc.W 139,38,183,292
  647.  
  648.     EndP
  649.  
  650.     EJECT
  651. *******************************************************************************
  652. *
  653. MainLoop    PROC
  654. *
  655. * Description:    This routine runs in a continuous loop until the user
  656. *    presses the mouse button. At that time, it ends. While
  657. *    it is looping, this routine checks Trigger, if the Trigger
  658. *    is set, it calls the walk routine to move the coin
  659. *
  660. *
  661. * Inputs:    None
  662. *
  663. * Outputs:    None
  664. *
  665. * External Refs:
  666. *
  667. * Entry Points:
  668.     Import DoWalk
  669. *
  670. *******************************************************************************
  671.     With Globals
  672.  
  673.     lda Trigger    ; test VBL Trigger value
  674.     beq EL0010    ; if its zero then don't move the coin
  675.  
  676.     jsr DoWalk    ; Walk a ball around a square
  677. EL0010
  678.     PushWord #0    ; get an event
  679.     PushWord #$FFFF
  680.     PushLong #EventRecord
  681.     _GetNextEvent
  682.  
  683.     pla
  684.     lda EventWhat
  685.     cmp #1    ; is it a mousedown???
  686.     bne MainLoop    ; if not get another event
  687.     rts    ; if so, then just end
  688.     EndP
  689.  
  690.     EJECT
  691. *******************************************************************************
  692. *
  693. CloseApp    Proc
  694. *
  695. * Description:    This routine removes all our heartbeat tasks at the end
  696. *    of the program.
  697. *
  698. *
  699. * Inputs:    None
  700. *
  701. * Outputs:    None
  702. *
  703. * External Refs:
  704.     Import TrigrTask
  705.     Import LightTask
  706.     Import ScrollTask
  707. *
  708. * Entry Points:
  709. *
  710. *******************************************************************************
  711.     PushLong #TrigrTask
  712.     _DelHeartBeat
  713.  
  714.     PushLong #ScrollTask
  715.     _DelHeartBeat
  716.  
  717.     PushLong #LightTask
  718.     _DelHeartBeat
  719.  
  720.     rts
  721.     EndP
  722.  
  723.  
  724.     EJECT
  725. *******************************************************************************
  726. *
  727. TriggerP    PROC
  728. *
  729. * Description:    Trigger heartbeat task. Every 1/60 of a second this routine
  730. *    will set a trigger value. The program can then read this 
  731. *    value and use it to base our coin animation.
  732. *
  733. *
  734. * Inputs:    None
  735. *
  736. * Outputs:    None
  737. *
  738. * External Refs:    None
  739. *
  740. * Entry Points:    None
  741.     Export TrigrTask
  742. *
  743. *******************************************************************************
  744.     With Globals
  745. TrigrTask    DC.L 0    ; heartbeat task header
  746. TrgTaskCnt    DC.W 3    ; Number of ticks before running
  747.     Dc.W $A55A    ; heartbeat task signature
  748.     
  749.     php    ; save the current proc state
  750.     REP #$30    ; set long A,I and M
  751.     lda #1    ; set the trigger to true
  752.     sta >Trigger    
  753.     lda #1    ; set the task up to be fired again
  754.     sta >TrgTaskCnt    ; in 1/60th of a second
  755.  
  756.     plp    ; restore the proc status
  757.     RTL    ; and leave this routine
  758.     endP
  759.  
  760.     EJECT
  761. *******************************************************************************
  762. *
  763. LightAnim    PROC
  764. *
  765. * Description:    Marquee ligh animation. This heartbeat task will switch the
  766. *    color table entries of color 9 and color 1 every 1/10 of
  767. *    a second. This will give the illusion of moving lights
  768. *    much like movie theatres used to use.
  769. *
  770. *
  771. * Inputs:    None
  772. *
  773. * Outputs:    None
  774. *
  775. * External Refs:    None
  776. *
  777. * Entry Points:    
  778.     Export LightTask
  779. *
  780. *******************************************************************************
  781. LightTask    DC.L 0
  782. LghTaskCnt    DC.W 5    ; number of ticks before running
  783.     Dc.W $A55A    ; heartbeat signature
  784.  
  785.     php    ; save the current processor state
  786.     Rep #$30    ; and set full 16 bit mode.
  787.  
  788.     PushWord #0    ; get the current color table entry
  789.     PushWord #0    ; for color #9
  790.     PushWord #9
  791.     _GetColorEntry
  792.     pla
  793.     sta >tempC1    ; and save it for later use
  794.  
  795.     PushWord #0    ; and get the color table entry for 
  796.     PushWord #0    ; color 1
  797.     PushWord #1
  798.     _GetColorEntry
  799.     pla
  800.     sta >tempC2    ; and save it for later
  801.  
  802.     PushWord #0    ; now set the entry for color #1
  803.     PushWord #1    ; to be that of what #9 was
  804.     PushWord >tempC1
  805.     _SetColorEntry
  806.  
  807.     PushWord #0    ; and set color #9 to what Color#1
  808.     PushWord #9    ; was
  809.     PushWord >tempC2
  810.     _SetColorEntry
  811.  
  812.  
  813.     lda #6    ; Re-arm the task to be fired again
  814.     Sta >LghTaskCnt    ; in 1/10th of a second
  815.     plp    ; restore the proc status
  816.     Rtl    ; and leave
  817. tempC1    ds.B 2
  818. tempC2    ds.B 2
  819.     EndP
  820.  
  821.     EJECT
  822. *******************************************************************************
  823. *
  824. ScrollAnim    Proc
  825. *
  826. * Description:    This routine will move an area of the screen over 4 pixels
  827. *    and wrap the stuff that falls off the edge to the end of
  828. *    the same line (to give the image of circular scrolling).
  829. *    This routine gets called aprox every 1/30th of a second
  830. *
  831. * Inputs:    None
  832. *
  833. * Outputs:    None
  834. *
  835. * External Refs:
  836. *
  837. * Entry Points:
  838.     Export ScrollTask
  839. *
  840. *******************************************************************************
  841.     With Globals
  842. ScrollTask    dc.L 0    ; Heartbeat task header
  843. ScrTaskCnt    dc.W 2
  844.     dc.W $A55A
  845.     
  846.     phd    ; save direct register
  847.     php    ; and proc status
  848.  
  849.     REP #$30    ; turn on full 16 bit mode...
  850.     lda >MyDP    ; get my Direct page
  851.     TCD    ; and make it current
  852.  
  853.     lda #46    ; starting scan line
  854.     sta Counter
  855.     lda #$E1
  856.     sta LinePt+2    ; set up high byte of scrn address
  857.  
  858. SA010    lda Counter    ; get starting address of scan line
  859.     asl A    ; multiply by 2!
  860.     tay
  861.     lda [ScreenTab],y    ; get next line of screen tab
  862.     sta LinePt    ; store it in our pointer
  863.     ldy #16    ; start out 8 bytes    in...
  864.     lda [LinePt],y    ; get first byte of    area
  865.     sta temp1    ; save it for later...
  866.  
  867.     ldy #142    ; end of rect to scroll
  868. SA020    lda [LinePt],y    ; get byte to scroll
  869.     tax    ; save it in X
  870.     lda temp1    ; get proper byte value
  871.     sta [LinePt],y    ; now save it...
  872.     txa    ; get saved value
  873.     sta temp1    ; and save it...
  874.     dey
  875.     dey
  876.     cpy #14    ; did we store the last one???
  877.     bne SA020
  878.     inc Counter    ; go to next line
  879.     lda Counter
  880.     cmp #82    ; are we done yet???
  881.     bne SA010    ; nope... not yet!
  882.  
  883.     lda #2    ; reset the task timer to 2 60th
  884.     sta >ScrTaskCnt    ; of a second (1/30th)
  885.  
  886.     plp    ; restore the previous processor flags
  887.     pld    ; and the direct page register
  888.  
  889.     rtl
  890.     EndP
  891.  
  892.     EJECT
  893. *******************************************************************************
  894. *
  895. DoWalk    PROC
  896. *
  897. * Description:    This routine erases the coin from the screen, when the
  898. *    coin hits an edge, this routine adjusts the increments
  899. *    properly.
  900. *
  901. *
  902. * Inputs:    None
  903. *
  904. * Outputs:    None
  905. *
  906. * External Refs:
  907.     Import DoErase
  908.     Import DoDraw
  909. *
  910. * Entry Points:
  911. *
  912. *******************************************************************************
  913.     With Globals
  914.  
  915.  
  916.     stz Trigger    ; clear the trigger for next time
  917.     jsr DoErase    ; erase the coin
  918.     lda CurX    ; test to see if we hit the left
  919.     cmp #20    ; edge
  920.     blt DW005    ; if so, then change directions
  921.     cmp #140    ; test the right edge
  922.     blt DW010    ; if not exceeded then check top & bottom
  923. DW005    lda #0    ; this will reverse the direction of
  924.     SEC    ; the coins horiz movement by negating
  925.     SBC DDXInc    ; the current x increment
  926.     sta DDXInc
  927.  
  928. DW010    lda CurY    ; now test the top and bottom
  929.     cmp #140    ; past the top?
  930.     blt DW015    ; if so, change dir
  931.     cmp #170    ; past the bottom?
  932.     blt DW020    ; if not skip the next section
  933. DW015    lda #0    ; negate the vertical increment
  934.     sec
  935.     sbc DDYInc
  936.     sta DDYInc
  937.  
  938. DW020
  939.     lda CurX    ; now that the increment is correct
  940.     clc    ; bump our location counters to
  941.     adc DDXInc    ; the new position
  942.     sta CurX
  943.     lda CurY
  944.     clc
  945.     adc DDYInc
  946.     sta CurY
  947.     jsr DoDraw    ; and re-draw the coin
  948. DW030
  949.     rts
  950.     EndP
  951.  
  952.     EJECT
  953. *******************************************************************************
  954. *
  955. DoErase    PROC
  956. *
  957. * Description:    This erases the coin from its current location
  958. *
  959. *
  960. * Inputs:    None
  961. *
  962. * Outputs:    None
  963. *
  964. * External Refs:
  965. *
  966. * Entry Points:
  967. *
  968. *******************************************************************************
  969.     With Globals
  970.  
  971. ; First calculate the starting scan line *2 and the ending scanline *2. Place
  972. ; the starting scan line into the X register and the ending in DDTemp
  973.  
  974.     lda CurY    ; get the Y posn and multiply it by 2
  975.     asl A    ; to get the current screen line offset 
  976.     tax    ; store for later use..
  977.     clc    ; add 24 to it (12 scan lines *2)
  978.     adc #24    ; to make the terminating value for
  979.     sta DDTemp    ; our loop
  980.  
  981. ; next calculates the memory location of the upper left hand corner
  982. ; of our object on the screen. This routine uses the scan line address table
  983. ; given to us by quickdraw. 
  984. DE010    txy    ; retrieve the current scan line index
  985.     lda CurX    ; get XCord in bytes. and Add it to
  986.     clc    ; the address of the current ycord scan
  987.     adc [ScreenTab],y    ; line to create the screen address. 
  988.     sta DDPoint1    ; Save it in Direct page so we can use
  989.     lda #$E1    ; it as a long pointer. NOTE: The screen
  990.     sta DDPoint1+2    ; is always in bank $E1
  991. ; Now that DDPoint1 contains the pointer we need start copying Black over the 
  992. ; screen area that the coin was in, two bytes at a time.
  993.  
  994.     ldy #$0000    ; zero the index
  995. DE0020    lda #$0000    ; erase with black...
  996.     sta [DDPoint1],y    ; save it to the screen
  997.     iny    ; bump our line counter 2
  998.     iny
  999.     cpy #6    ; are we done with current line???
  1000.     bne DE0020    ; if not do another word
  1001.     inx    ; if so bump the screen line tbl offset
  1002.     inx    ; by two
  1003.     cpx DDTemp    ; see if we finished the whole picture
  1004.     bne DE010    ; if not, draw the next line
  1005.     rts    ; if so, then end.
  1006.     EndP
  1007.  
  1008.     EJECT
  1009. *******************************************************************************
  1010. *
  1011. DoDraw    PROC
  1012. *
  1013. * Description:    This draws the coin at its current location
  1014. *
  1015. *
  1016. * Inputs:    None
  1017. *
  1018. * Outputs:    None
  1019. *
  1020. * External Refs:
  1021. *
  1022. * Entry Points:
  1023. *
  1024. *******************************************************************************
  1025.     With Globals
  1026.  
  1027. ; First calculate the starting scan line *2 and the ending scanline *2. Place
  1028. ; the starting scan line into the X register and the ending in DDTemp
  1029.  
  1030.     lda CurY    ; get the Y posn and multiply it by 2
  1031.     asl A    ; to get the current screen line offset 
  1032.     tax    ; store for later use..
  1033.     clc    ; add 24 to it (12 scan lines *2)
  1034.     adc #24    ; to make the terminating value for
  1035.     sta DDTemp    ; our loop
  1036.  
  1037.     lda MyBitMap    ; get address for my coin data
  1038.     sta DDPoint2    ; and store it in a direct page ptr
  1039.     lda MyBitMap+2
  1040.     sta DDPoint2+2
  1041.  
  1042. ; next calculates the memory location of the upper left hand corner
  1043. ; of our object on the screen. This routine uses the scan line address table
  1044. ; given to us by quickdraw. 
  1045. DD010    txy    ; retrieve the current scan line index
  1046.     lda CurX    ; get XCord in bytes. and Add it to
  1047.     clc    ; the address of the current ycord scan
  1048.     adc [ScreenTab],y    ; line to create the screen address. 
  1049.     sta DDPoint1    ; Save it in Direct page so we can use
  1050.     lda #$E1    ; it as a long pointer. NOTE: The screen
  1051.     sta DDPoint1+2    ; is always in bank $E1
  1052. ; Now that DDPoint1 contains the pointer we need start copying the coin data 
  1053. ; to the screen, two bytes at a time.
  1054.  
  1055.     ldy #$0000    ; zero the index
  1056. DD0020    lda [DDPoint2],y    ; get the next byte of data to copy
  1057.     sta [DDPoint1],y    ; save it to the screen
  1058.     iny    ; bump the byte counter by 2
  1059.     iny
  1060.     cpy #6    ; are we done with line???
  1061.     bne DD0020    ; if not, do another word
  1062.  
  1063.     lda DDPoint2    ; Now bump up pointer to
  1064.     clc    ; the BitMap
  1065.     adc #6    ; by RowBytes....
  1066.     sta DDPoint2
  1067.     inx    ; bump the screen line...
  1068.     inx    ; by two (tbl offset)
  1069.     cpx DDTemp    ; see if we done whole picture
  1070.     bne DD010    ; nope do next line
  1071.     rts
  1072.     EndP
  1073.  
  1074.     END
  1075.  
  1076.